<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>浏览器模拟器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .browser-container {
            width: 100%;
            max-width: 1200px;
            margin: 0 auto;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        .browser-header {
            display: flex;
            padding: 10px;
            background-color: #f1f1f1;
            border-bottom: 1px solid #ddd;
        }
        .browser-controls {
            display: flex;
            margin-right: 10px;
        }
        .browser-button {
            width: 30px;
            height: 30px;
            margin-right: 5px;
            border: none;
            border-radius: 4px;
            background-color: #e0e0e0;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
        }
        .browser-button:hover {
            background-color: #d0d0d0;
        }
        .browser-address-bar {
            flex: 1;
            display: flex;
        }
        .browser-address-input {
            flex: 1;
            padding: 8px 15px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 14px;
        }
        .browser-go-button {
            margin-left: 5px;
            padding: 8px 15px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .browser-go-button:hover {
            background-color: #45a049;
        }
        .browser-content {
            height: 600px;
            width: 100%;
            border: none;
        }
        .status-bar {
            padding: 5px 10px;
            background-color: #f1f1f1;
            border-top: 1px solid #ddd;
            font-size: 12px;
            color: #666;
        }
    </style>
</head>
<body>
    <div class="browser-container">
        <div class="browser-header">
            <div class="browser-controls">
                <button class="browser-button" onclick="goBack()">←</button>
                <button class="browser-button" onclick="goForward()">→</button>
                <button class="browser-button" onclick="reloadPage()">↻</button>
            </div>
            <div class="browser-address-bar">
                <input type="text" class="browser-address-input" id="urlInput" value="https://joey862.github.io/Joey.github.io/">
                <button class="browser-go-button" onclick="loadUrl()">前往</button>
            </div>
        </div>
        <iframe id="browserFrame" class="browser-content" src=""></iframe>
        <div class="status-bar" id="statusBar">就绪</div>
    </div>

    <script>
        const browserFrame = document.getElementById('browserFrame');
        const urlInput = document.getElementById('urlInput');
        const statusBar = document.getElementById('statusBar');

        function loadUrl() {
            let url = urlInput.value.trim();
            
            // 添加http://前缀如果不存在
            if (!url.startsWith('http://') && !url.startsWith('https://')) {
                url = 'https://' + url;
                urlInput.value = url;
            }
            
            try {
                browserFrame.src = url;
                statusBar.textContent = `正在加载: ${url}`;
            } catch (e) {
                statusBar.textContent = `错误: ${e.message}`;
            }
        }

        function goBack() {
            try {
                browserFrame.contentWindow.history.back();
                statusBar.textContent = '返回上一页';
            } catch (e) {
                statusBar.textContent = '无法返回: ' + e.message;
            }
        }

        function goForward() {
            try {
                browserFrame.contentWindow.history.forward();
                statusBar.textContent = '前进下一页';
            } catch (e) {
                statusBar.textContent = '无法前进: ' + e.message;
            }
        }

        function reloadPage() {
            try {
                browserFrame.contentWindow.location.reload();
                statusBar.textContent = '重新加载页面';
            } catch (e) {
                statusBar.textContent = '无法重新加载: ' + e.message;
            }
        }

        // 监听键盘事件，按Enter键加载URL
        urlInput.addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                loadUrl();
            }
        });

        // 监听iframe加载事件
        browserFrame.addEventListener('load', function() {
            statusBar.textContent = `已加载: ${browserFrame.src}`;
            urlInput.value = browserFrame.src;
        });

        // 监听iframe错误事件
        browserFrame.addEventListener('error', function() {
            statusBar.textContent = '加载页面时出错';
        });
    </script>
</body>
</html>
